package com.itcncp.ucenter.rpc.service.impl;

import com.itcncp.common.annotation.BaseService;
import com.itcncp.common.base.BaseServiceImpl;
import com.itcncp.ucenter.dao.mapper.ItcsCityInfoMapper;
import com.itcncp.ucenter.dao.model.ItcsCityInfo;
import com.itcncp.ucenter.dao.model.ItcsCityInfoExample;
import com.itcncp.ucenter.rpc.api.ItcsCityInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* ItcsCityInfoService实现
* Created by itcncp on 2018/1/12.
*/
@Service
@Transactional
@BaseService
public class ItcsCityInfoServiceImpl extends BaseServiceImpl<ItcsCityInfoMapper, ItcsCityInfo, ItcsCityInfoExample> implements ItcsCityInfoService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ItcsCityInfoServiceImpl.class);

    @Autowired
    ItcsCityInfoMapper itcsCityInfoDao;

    //根据城市查询是否有限行信息
    @Override
    @Cacheable(value = "itcncp-ucenter-rpc-service-ehcache", key = "'selectIsXianxingInfo_' + #city")
    public ItcsCityInfo getIsXianxingCity(String city){

        ItcsCityInfoExample cityInfoExample = new ItcsCityInfoExample();
        //限行城市 2不限行 1限行城市
        cityInfoExample.createCriteria().andIsxianxingEqualTo( 1 ).andCityNameLike( "%"+city+"%" );

        List<ItcsCityInfo> list = itcsCityInfoDao.selectByExample( cityInfoExample );

        if(null !=list && list.size()>0){
            return  list.get( 0 );
        }

        return  null;
    }


}